package com.nursery.kindergarten.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nursery.kindergarten.dao.KindergartenInfoMapper;
import com.nursery.kindergarten.entity.KindergartenInfo;
import com.nursery.kindergarten.entity.KindergartenInfoExample;
import com.nursery.kindergarten.service.KindergartenInfoService;

@Service
public class KindergartenInfoServiceImpl implements KindergartenInfoService {

	@Autowired
	KindergartenInfoMapper kindergartenInfoMapper;

	public long countByExample(KindergartenInfoExample example) {
		return kindergartenInfoMapper.countByExample(example);
	}

	public void deleteByPrimaryKey(Integer id) throws Exception {
		kindergartenInfoMapper.deleteByPrimaryKey(id);
	}

	public void insert(KindergartenInfo record) throws Exception {
		kindergartenInfoMapper.insertSelective(record);
	}

	public List<KindergartenInfo> selectByExample(KindergartenInfoExample example) {
		return kindergartenInfoMapper.selectByExample(example);
	}

	public KindergartenInfo selectByPrimaryKey(Integer id) {
		return kindergartenInfoMapper.selectByPrimaryKey(id);
	}

	public void updateByPrimaryKeySelective(KindergartenInfo record) throws Exception {
		kindergartenInfoMapper.updateByPrimaryKeySelective(record);
	}

	public void updateByPrimaryKey(KindergartenInfo record) throws Exception {
		kindergartenInfoMapper.updateByPrimaryKey(record);
	}

	public String getNameById(Integer id) {
		KindergartenInfoExample example = new KindergartenInfoExample();
		KindergartenInfoExample.Criteria criteria = example.createCriteria();
		criteria.andIdEqualTo(id);
		KindergartenInfo info = kindergartenInfoMapper.selectByExample(example).stream().findFirst().orElse(null);
		if (info == null) {
			return "";
		} else {
			return info.getKindName();
		}
	}

}
